import requests
from util.log import logger

url = 'http://132.228.28.193:8080/databusmtr/api/report'

http = requests.Session()

headers = {
    'User-Agent': 'SYSTEM_MONITOR',
    'Content-type': 'application/json; charset=utf-8',
    'Accept': 'application/json'}

http.headers.update(headers)


def report(data):
    try:
        rsp = http.post(
            url,
            json=data,
            timeout=2
        )
        if rsp.status_code != 200:
            logger.info('状态异常: %s' % rsp.status_code)
        else:
            logger.info('请求成功: %s' % rsp.text)
    except requests.exceptions.Timeout as e:
        logger.info('请求结果: fail,超时')
    except requests.exceptions.RequestException as e:
        logger.info('请求结果: fail,异常')
